
#include <fstream>
#include <cstdio>
#include "Context/Gameplay/Track.h"

namespace Context {

Track::Track(std::string trackName) :
	Visual("Gameplay"),
	Reason("Gameplay"),
	Sense("Gameplay"),
	trackGfx(trackName, "track", -1) {
	/* load the collision map */
	char trackfn[1024];
	char c; // used to store the collision info;
	std::string line;
	std::sprintf(trackfn, "track/%s/%s.colmap", trackName.c_str(), trackName.c_str());
	std::fstream collisionFile(trackfn);
	size.x = size.y = 0;
	while (!collisionFile.eof()) {
		std::getline(collisionFile, line);
		std::vector<bool> colLine;
		for (std::string::iterator stri = line.begin(); stri != line.end(); stri++) {
			c = *stri;
			if (c == 'x') colLine.push_back(true);
			else colLine.push_back(false);
			std::printf("%c", c);
		}
		trackMap.push_back(colLine);
		std::printf("\n");
	};
	size.x = (trackMap[0].size())*32;
	size.y = (trackMap.size()-1)*32;
	std::printf("%f x %f\n",size.x, size.y); 
}

 Track::~Track() {
}

// Asks for generation of a graphical model to be displayed
Engine::Resource::GraphicList Track::display() {
	Engine::Resource::GraphicList gfxList;
	gfxList.push_back(&trackGfx);
	return gfxList;
}

void Track::pulse(int delta) {
}


} // namespace Context
